/****************************************Copyright (c)**************************************************
**                                         2016-03
**
**                                
**
**
**--------------File Info-------------------------------------------------------------------------------
** File name:		    ht6x1x_pmu.c
** Last modified Date:  2016-03-29
** Last Version:		v1.0
** Descriptions:		
**
**------------------------------------------------------------------------------------------------------
** Created by:			Evan Chen
** Created date:		2016-03-29
** Version:				v1.0
** Descriptions:		
**
**------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
** Version:
** Descriptions:
**
********************************************************************************************************/

/* Includes ------------------------------------------------------------------*/
#include "ht6x1x_pmu.h"
#include "ht6x1x_flash.h"

void PMU_PowerModeSet(uint16_t mode)
{
	WPREG_Disable();
	
	HT_PMU->PMUCON = mode;

	WPREG_Enable();
}

void PMU_PowerLevelSet(uint16_t vcclvl, uint16_t borlvl)
{
	//HT_PMU->VDETCFG &= ~(VDETCFG_VCC_LVL_MASK | VDETCFG_BOR_LVL_MASK);
	HT_PMU->VDETCFG = vcclvl | borlvl | VDETCFG_VCC_LVL_FLAG;	
}

void PMU_Enable(PMU_Enable_TypeDef enable)
{
	HT_PMU->PMUIF &= ~enable;
	HT_PMU->PMUIE |= enable;
}

void PMU_Disable(PMU_Enable_TypeDef enable)
{
	HT_PMU->PMUIF &= ~enable;
	HT_PMU->PMUIE &= ~enable;
}

void PMU_ClearState(void)
{
	HT_PMU->PMUSTA = 0;
}

uint16_t PMU_ReadState(PMU_Enable_TypeDef type)
{
	return (HT_PMU->PMUSTA &  type);
}

void PMU_SetVdetTime(uint16_t time)
{
	HT_PMU->VDETPCFG = time;
}

